package org.kisekiproject.evaluator.nodes {
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	/**
	 * Unary operator.
	 */
	public class UnaryOperatorNode extends EventDispatcher implements ISyntaxNode {

		private var _operator:String;
		private var _operand:ISyntaxNode;
		private var _index:int;

		/**
		 * Constructor.
		 */
		public function UnaryOperatorNode(op:String, operand:ISyntaxNode, index:int) {
			_operator=op;
			_operand=operand;
			_index=index;

			_operand.addEventListener(Event.CHANGE, onDependencyChange);
		}

		/**
		 * Dependency change.
		 */
		private function onDependencyChange(event:Event):void {
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		/**
		 * Get value.
		 */
		public function get value():Object {
			switch (_operator) {
				case "-":
					return -Number(_operand.value);
					break;

				default:
					throw new Error("Unkown operator: "+_operator);
			}
			return null;
		}

		/**
		 * Get index.
		 */
		public function get index():int {
			return _index;
		}
	}
}